from typing import List
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session

from app.db.session import get_db
from app.models.mcp_tool import MCPCategory
from app.schemas.mcp_tool import MCPCategory as MCPCategorySchema
from app.schemas.mcp_tool import MCPCategoryCreate, MCPCategoryUpdate
from app.services.mcp_tool import MCPCategoryService

router = APIRouter()


@router.get("/", response_model=List[MCPCategorySchema])
def get_categories(db: Session = Depends(get_db)):
    """
    获取所有分类
    """
    return MCPCategoryService.get_categories(db)


@router.get("/{category_id}", response_model=MCPCategorySchema)
def get_category(category_id: int, db: Session = Depends(get_db)):
    """
    获取指定ID的分类
    """
    return MCPCategoryService.get_category(db, category_id)


@router.post("/", response_model=MCPCategorySchema)
def create_category(category: MCPCategoryCreate, db: Session = Depends(get_db)):
    """
    创建新分类
    """
    return MCPCategoryService.create_category(db, category)


@router.put("/{category_id}", response_model=MCPCategorySchema)
def update_category(category_id: int, category: MCPCategoryUpdate, db: Session = Depends(get_db)):
    """
    更新分类
    """
    return MCPCategoryService.update_category(db, category_id, category)


@router.delete("/{category_id}")
def delete_category(category_id: int, db: Session = Depends(get_db)):
    """
    删除分类
    """
    MCPCategoryService.delete_category(db, category_id)
    return {"message": "分类已删除"} 